<template>
  <div>
    用户名：<input
      v-model="username"
      type="text"
    >密码：<input
      v-model="password"
      type="password"
    ><button @click="login">
      login
    </button>
  </div>
</template>

<script>
import { getUser } from '@/api/user';

export default {
  data() {
    return {
      username: '',
      password: '',
    };
  },
  methods: {
    localset(name, data) {
      localStorage.setItem(name, JSON.stringify(data));
    },
    async login() {
      if (this.username === 'isenTang' && this.password === 12341234) {
        const user = await getUser({
          username: this.username,
          password: this.password,
        });
        this.localset('user', user);
        this.$router.push('/restaurant');
      }
    },
  },
};
</script>

<style lang="scss" scoped>

</style>
